package org.blogwu.jvm_learn.controller;


import org.blogwu.jvm_learn.bean.User;
import org.blogwu.learn.jvmlearn.Metaspace;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping("/d1/")
public class MemoryController {

    private List<User> userList = new ArrayList<>();

    private List<Class<?>> classList = new ArrayList<>();


    /**
     * -Xmx32m -Xms32m
     *
     * @return
     */
    @GetMapping("heap")
    public String heap() {
        long i = 0;
        while (true) {
            userList.add(new User(i, UUID.randomUUID().toString()));
            i = i + 1;
        }
    }


    /**
     * -XX:MetaspaceSize=32m  -XX:MaxMetaspaceSize=32m
     *
     * @return
     */
    @GetMapping("nonheap")
    public String nonHeap() {
        int i = 0;
        while (true) {
            classList.addAll(Metaspace.creatClass());
        }
    }


    public static void main(String[] args) {
        long i = 0;
        List<User> userList1 = new ArrayList<>();
        while (true) {
            userList1.add(new User(i, UUID.randomUUID().toString()));
            i = i + 1;
        }
    }

}
